/*************************************************************************
	> File Name: P1160.cpp
	> Author: 
	> Mail: 
	> Created Time: 
 ************************************************************************/
#include <iostream>
#include <list>
#define MAX_N 100005
using namespace std;

list<int>::iterator pos[MAX_N];
int visit[MAX_N + 5] = {0};
list<int> node;

int main() {
    node.push_back(1);
    pos[1] = node.begin();
    int n; cin >> n;
    for (int i = 2; i <= n; i++) {
        int k, p; cin >> k >> p;
        if (p == 0) {
            pos[i] = node.insert(pos[k], i);
        } else {
            pos[i] = node.insert(next(pos[k]), i);
        }
    }
    int m, x; cin >> m;
    while (m--) {
        cin >> x;
        if (visit[x]) continue;
        node.erase(pos[x]);
        visit[x] = 1;
    }
    for (auto &i : node) cout << i << " ";
    cout << endl;
    return 0;
}
